'use strict';

module.exports = function createUpdatedCollection(collectionA, objectB) {
  let object={};
  let arr=[];
  for(let item of collectionA){
    if(item.length===1){
      if(!object[item]){
      object[item]={};
      object[item].key=item;
      object[item].count=1;
    }
    else {
      object[item].count++;
    }
   }
   else if((item.length===3)) {
    let arr1=item.split("");
    if(!object[arr1[0]]){
     object[arr1[0]]={};
     object[arr1[0]].key=arr1[0];
     object[arr1[0]].count=parseInt(arr1[2]);
    }
    else{
      object[arr1[0]].count=object[arr1[0]].count + parseInt(arr1[2]);
    }
   } 
  }
  for(let i in object){
    arr.push(object[i]);
  }
  for(let i of objectB['value']){
    for(let j of arr){
      if(i===j.key){
        j.count-=parseInt(j.count/3);
      }
    }
  }
  return arr;
}
